execfile('v4/base.py')

class HighF(Base):
    def __init__(self):
        self.bar_count_default = 50
        self.end_date_str = '20250831'  # 如果需要可以取消注释
        # self.start_date_str = '2025-06-16'  # 如果需要可以取消注释

    
    def mark_h_d(self,df):
        df = df.copy().sort_values(by=['code', 'date'])
        # 生成特征 h_d20、h_d40、h_d60
        for window in [20, 40, 60]:
            high_col = f'high_{window}'
            df[high_col] = df.groupby('code')['high'].transform(
                lambda x: x.rolling(window=window, min_periods=1).max()
            )
            df[f'h_d{window}'] = (
                (df['close'] - df[high_col]) / df[high_col].replace(0, 1) * 100
            ).round(2)
        return df.drop(columns=[f'high_{w}' for w in [20,40,60]])